package com.wwj.core.system.entity;

import com.wwj.framework.entity.BaseIdEntity;
import net.sf.json.JSONArray;

import java.util.Arrays;

/**
 * Created by xya on 16-10-24.
 */
public class Role extends BaseIdEntity<Integer> {

    private static final long serialVersionUID = -281224000474132875L;

    private String code;
    private String name;
    private String remark;
    private Integer status;

    private Integer[] menuIds;
    private String menuIds2Json;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer[] getMenuIds() {
        if(null == menuIds && null != menuIds2Json && !"".equals(menuIds2Json)){
            JSONArray arr = JSONArray.fromObject(menuIds2Json);
            Object[] objArr = arr.toArray();
            menuIds = new Integer[objArr.length];
            for(int i=0,len=objArr.length;i<len;i++){
                menuIds[i] = (Integer) objArr[i];
            }
            Arrays.sort(menuIds);
            return menuIds;
        }
        return menuIds;
    }

    public void setMenuIds(Integer[] menuIds) {
        this.menuIds = menuIds;
    }

    public String getMenuIds2Json() {
        if((null == menuIds2Json || "".equals(menuIds2Json)) && null != menuIds)
            menuIds2Json = JSONArray.fromObject(menuIds).toString();
        return menuIds2Json;
    }

    public void setMenuIds2Json(String menuIds2Json) {
        this.menuIds2Json = menuIds2Json;
    }
}
